package com.ChenScreenPro;

import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.FFmpegFrameRecorder;
import org.bytedeco.javacv.Frame;

/**
 * ClassName: AudioGrabber
 * Package: com.ChenScreenPro
 * Description:
 *
 * @Author 谢伟
 * @Create 2024/6/11 4:42
 * @Version 1.0
 */
public class AudioGrabber {
    private FFmpegFrameGrabber grabber;

    public void startGrabber(FFmpegFrameRecorder recorder) throws FFmpegFrameGrabber.Exception {
        Frame frame = grabber.grabSamples();
        if (frame != null) {
            try {
                recorder.recordSamples(48000, 2, frame.samples);
            } catch (FFmpegFrameRecorder.Exception e) {
                e.printStackTrace();
            }
        }
    }

    public void initGrabber() throws FFmpegFrameGrabber.Exception {
//        grabber = new FFmpegFrameGrabber("audio=麦克风阵列 (适用于数字麦克风的英特尔® 智音技术)");//这里是对开发者本人的电脑进行的测试
        grabber = new FFmpegFrameGrabber("audio=virtual-audio-capturer");
        grabber.setFormat("dshow");
        grabber.start();
    }
    public void stopGrabber() throws FFmpegFrameGrabber.Exception {
        grabber.stop();
        grabber.release();
    }
}
